import { AUDIT_STATUS } from '@utility/dict'

export function buildAuditFlowData(steps) {
  if (steps && steps.length) {
    return steps.map((item) => {
      const fields = []
      if (item.createTime) {
        fields.push({
          value: item.createTime,
        })
      }
      if (item.userName) {
        fields.push({
          label: '执行人',
          value: item.userName,
        })
      }
      if (item.reason) {
        fields.push({
          label: '意见',
          value: item.reason,
        })
      }
      return {
        id: item.id,
        title: AUDIT_STATUS[item.status],
        operated: item.flowStatus !== '0',
        passed: ![AUDIT_STATUS.bzReject, AUDIT_STATUS.zrReject].includes(item.status),
        fields: fields,
        status: item.status,
      }
    })
  }
  return null
}
